#ifndef __SPWM_INT_H__
#define __SPWM_INT_H__

/*基于整数运算的正弦PWM波*/



//宏定义
#define SINE_COUNT 128
#define SINE_COUNT_LITE 33
#define TIMER_ARR_MAX 7500  //96M/7500=12800Hz  0-7500
#define TIMER_FREQ 96000000
//#define AC_FREQ 50 //单位Hz
//#define AC_FREQ_CAL  (AC_FREQ*100)   //计算时扩大100的整型表示
#define PLUSE_COUNT_50Hz (TIMER_FREQ>>8)  
//(TIMER_FREQ / 256) //定时器输入频率/载波比, 依据公式：2*N载波比*调制频率=定时器频率/x计数溢出


typedef struct{
    unsigned char sinCycle:2;  //sin的周期，表示0-3
}SPWM_VAR;


extern unsigned short M; //(PLUSE_COUNT_50Hz / (AC_FREQ / 100))/2;            //调制比=调制波峰值/载波峰值,定时器最大比较值9600,当M=1时,取9600.这里取为调制波峰值
//调制最大值不是限定为9600，而是由当前输出频率确定
extern unsigned short N;             //载波比=载波频率/调制波频率,即50Hz内承载200个载波，即50*200=10kHz
extern unsigned short SPWMCnt;         //由0递增到调制比
extern unsigned char SinCnt;           //sin正弦数组计数由0递增到128 =(SPWMCnt/N)*128=SPWMCnt*128/N
extern unsigned short SPWM_Freq; //SPWM调制波频率,*1000倍
extern unsigned short AC_DetectFreq;   //探测到的交流频率
extern unsigned short TimerArr_50Hz;
extern unsigned short sine_Int[SINE_COUNT];
//extern unsigned short sineLite_Int[SINE_COUNT];

extern unsigned short AC_FREQ;

void sineValue_update(void);

#endif